package org.agile2soft.nexoma.tapestry.pages;

import java.util.List;

import org.agile2soft.nexoma.core.controller.ServiceController;
import org.agile2soft.nexoma.core.controller.ServiceOptionController;
import org.agile2soft.nexoma.core.controller.ServicesGroupController;
import org.agile2soft.nexoma.core.entity.ServiceOption;
import org.agile2soft.nexoma.core.entity.ServicesGroup;
import org.agile2soft.nexoma.tapestry.model.ApplicationContainer;
import org.apache.tapestry5.PersistenceConstants;
import org.apache.tapestry5.RenderSupport;
import org.apache.tapestry5.annotations.AfterRender;
import org.apache.tapestry5.annotations.IncludeJavaScriptLibrary;
import org.apache.tapestry5.annotations.PageActivationContext;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;

@IncludeJavaScriptLibrary("context:resources/js/Portal.js")
public class Service {
	
	@PageActivationContext
	private Service service;

    @Persist(PersistenceConstants.FLASH)
    private String messageCode;

    public String getMessageCode ( String message ) {
        return messageCode;
    }

    public void setMessageCode ( String messageCode ) {
        this.messageCode = messageCode;
    }

    @Inject
    private Messages _messages;

    public String getMessage() {
        return ( messageCode!=null ) ? _messages.get(messageCode) : null;
    }

    @Inject
    private RenderSupport _renderSupport;

    @AfterRender
    void afterRender() {
        _renderSupport.addInit("portalmanager","portalmanager");
    }

    @Inject
    @Property
    private ApplicationContainer appContainer;

    @Property
    private ServicesGroup group;

    @Property
    private ServiceOption option;

    @Inject
    private ServiceController serviceController;

    @Inject
    private ServicesGroupController serviceGroupController;

    @Inject
    private ServiceOptionController optionController;

    public List<ServicesGroup> getGroups () {
        return serviceGroupController.findAll();
    }

}
